<template>
  <div class="sn8">
    <el-card
      class="aui-card--fill"
      shadow="never">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item>
          <el-input
            clearable
            :placeholder="$t('mike.sn8')"
            v-model="dataForm.sn8"/>
        </el-form-item>

        <el-form-item >

          <el-input
            clearable
            :placeholder="$t('model.name')"
            v-model="dataForm.name">

            <el-button
              @click="getDataList()"
              slot="append">
              <i class="el-icon-search"/>
            </el-button>
          </el-input>
        </el-form-item>
        <el-form-item/>
        <el-form-item>
          <el-button
            @click="clickOnAddOrUpdate()"
            type="primary"
          >
            <i class="el-icon-plus"/>
          </el-button>
        </el-form-item>
      </el-form>

      <div class="sn8-table">

        <el-table
          :data="dataList"
          border
          style="width: 100%;"
          v-loading="dataListLoading"
        >

          <el-table-column
            :label="$t('model.name')"
            align="center"
            header-align="center"
            prop="name"
          />
          <el-table-column
            :label="$t('mike.sn8')"
            align="center"
            header-align="center"
            prop="sn8"
          />
          <el-table-column
            :label="$t('mike.sellType')"
            align="center"
            header-align="center"
            prop="sellType"
          />

          <el-table-column
            :label="$t('model.createTime')"
            align="center"
            header-align="center"
            prop="createTime"
          />

          <el-table-column
            :label="$t('handle')"
            align="center"
            fixed="right"
            header-align="center"
            width="160"
          >
            <template slot-scope="scope">
              <el-button
                @click="clickOnAddOrUpdate(scope.row.id)"
                size="small"
                type="primary"
              >
                {{ $t("update") }}
              </el-button>
              <el-button
                @click="deleteHandle(scope.row.id)"
                size="small"
                type="danger"
              >{{ $t("delete") }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          :current-page="page"
          :page-size="limit"
          :page-sizes="[10, 20, 50, 100]"
          :total="total"
          @current-change="pageCurrentChangeHandle"
          @size-change="pageSizeChangeHandle"
          layout="total, sizes, prev, pager, next, jumper"
        />
        <!-- 弹窗, 新增 / 修改 -->
        <add-or-update
          @refreshDataList="getDataList"
          ref="addOrUpdate"
          v-if="addOrUpdateVisible"
        />

      </div>
    </el-card>
  </div>
</template>

<script>
import AddOrUpdate from './sn8-add-or-update'
import mixinViewModule from '@/mixins/mike.view-module'
export default {
  name: 'Sn8',
  mixins: [mixinViewModule],
  components: { AddOrUpdate },
  data () {
    return {
      mixinViewModuleOptions: {
        loading: false,
        getDataListURL: '/midea/menu/sn8/get/all',
        deleteURL: '/midea/menu/sn8/del/'
      },
      dataForm: {
        sn8: '',
        name: ''
      }
    }
  },
  mounted () {
    this.getDataList()
  },
  methods: {
    clickOnAddOrUpdate (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.dataForm.id = id
        this.$refs.addOrUpdate.init()
      })
    }
  }

}
</script>

<style scoped lang="scss">

</style>
